// 这里是定义菜单的地方，详情请查看 https://electronjs.org/zh/docs/api/menu
import type {MenuItem, MenuItemConstructorOptions} from "electron";
import {BrowserWindow, dialog} from "electron";
import packageInfo from "../../../package.json";
import * as diyConst from "../config/const";

function platform() {
	if (process.platform === "darwin") return "Mac OS";
	return process.platform;
}

const type = platform();
const release = process.getSystemVersion();
const arch = process.arch;

function info() {
	dialog
		.showMessageBox({
			title: "关于",
			type: "info",
			message: `${packageInfo.title}`,
			detail: `版本信息：${packageInfo.version}\n引擎版本：${process.versions.v8}\n当前系统：${type} ${arch} ${release}`,
			noLink: true,
			buttons: ["官网", "确定"],
		})
		.then((r) => {
			console.log(r);
			if (r.response === 0) {
				const win = new BrowserWindow({width: 800, height: 600});
				// Load a remote URL
				win.loadURL(diyConst.GwLink);
				// Or load a local HTML file
				// win.loadFile('index.html')
			}
		});
}

const menu: Array<MenuItemConstructorOptions | MenuItem> = [
	{
		label: "设置",
		submenu: [
			{
				label: "快速重启",
				accelerator: "F5",
				role: "reload",
			},
			{
				label: "退出",
				accelerator: "CmdOrCtrl+F4",
				role: "close",
			},
		],
	},
	{
		label: "编辑",
		submenu: [
			{
				label: "撤销",
				accelerator: "CmdOrCtrl+Z",
				role: "undo",
			},
			{
				label: "重做",
				accelerator: "Shift+CmdOrCtrl+Z",
				role: "redo",
			},
			{
				label: "剪切",
				accelerator: "CmdOrCtrl+X",
				role: "cut",
			},
			{
				label: "复制",
				accelerator: "CmdOrCtrl+C",
				role: "copy",
			},
			{
				label: "粘贴",
				accelerator: "CmdOrCtrl+V",
				role: "paste",
			},
		],
	},
	{
		label: "帮助",
		submenu: [
			{
				label: "关于",
				click: info,
			},
		],
	},
];

export default menu;
